import { Modal, Space, message, Button, Dropdown, Menu } from "antd";
import { CloudDownloadOutlined, CloudUploadOutlined } from "@ant-design/icons";
import { useState, forwardRef, useImperativeHandle } from "react";
import { WAIT_SHIP, SHIPPED } from "@/views/utils/constant";
import SelectActions from "@/views/components/SelectActions";

const LeftBtns = (props, ref) => {
	const { type, selectedRows, handleCommand, searchForm, pagination, fetchList } = props;

	function isCheck(fn) {
		if (selectedRows.length > 0 || 1) {
			fn && fn(selectedRows);
		} else {
			message.warning("请先勾选订单数据");
		}
	}

	return (
		<Space>
			{type == WAIT_SHIP && (
				<>
					<SelectActions
						onClick={key => props.handleCommand("手动发货", { selectedRows, key, searchForm, type })}
						options={[
							{
								label: "筛选项",
								key: 2,
							},
							{
								label: "勾选项",
								key: 1
							}
						]}
					>
						<Button type="text">手动发货</Button>
					</SelectActions>
					<SelectActions
						name="合格证批量打印"
						onClick={() => isCheck(() => props.handleCommand("合格证批量打印", { selectedRows }))}
					/>
					<SelectActions
						name="快递批量打印"
						onClick={() => isCheck(() => props.handleCommand("快递批量打印", { selectedRows, fetchList }))}
					/>
				</>
			)}

			<SelectActions
				onClick={key => {
					const data = { searchForm, selectedRows, key, pagination };
					if (key === "导出勾选项") {
						isCheck(() => {
							props.handleCommand("导出", data);
						});
					} else {
						props.handleCommand("导出", data);
					}
				}}
				options={[
					{
						label: "导出所有项"
					},
					{
						label: "导出筛选项"
					},
					{
						label: "导出勾选项"
					}
				]}
			>
				<CloudDownloadOutlined className="main-color" />
				导出
			</SelectActions>
		</Space>
	);
};
export default forwardRef(LeftBtns);
